import http from '@/api'
import { RoleQuery, RoleVO, RoleDeptTree } from '@/api/interface/system/role'
import { UserVO, UserQuery } from '@/api/interface/system/user'
import { RoleMenuTree } from '@/api/interface/system/menu'
/**
 * @name 查询角色信息列表
 * @param query 参数
 * @returns 返回列表
 */
export const listRoleApi = (query: RoleQuery) => {
  return http.get<RoleVO[]>('/system/role/list', query, { loading: true })
}

/**
 * @name 根据角色ID查询部门树结构
 * @param roleId 角色Id
 * @returns 返回列表
 */
export const deptTreeSelectApi = (roleId: string | number) => {
  return http.get<RoleDeptTree>(`/system/role/deptTree/${roleId}`)
}

/**
 * @name 根据角色ID查询菜单下拉树结构
 * @param roleId 角色Id
 * @returns 返回列表
 */
export const roleMenuTreeSelectApi = (roleId: any) => {
  return http.get<RoleMenuTree>(`/system/menu/roleMenuTreeselect/${roleId}`)
}

/**
 * @name 查询角色信息详细
 * @param roleId roleId
 * @returns returns
 */
export const getRoleApi = (roleId: string | number) => {
  return http.get<RoleVO>(`/system/role/${roleId}`)
}

/**
 * @name 新增角色信息
 * @param data data
 * @returns returns
 */
export const addRoleApi = (data: any) => {
  return http.post<any>('/system/role', data, { loading: false })
}

/**
 * @name 修改角色信息
 * @param data data
 * @returns returns
 */
export const updateRoleApi = (data: any) => {
  return http.put<any>('/system/role', data, { loading: false })
}

/**
 * @name 角色数据权限
 * @param data data
 * @returns returns
 */
export const dataScopeApi = (data: any) => {
  return http.put<any>('/system/role/dataScope', data, { loading: false })
}

/**
 * @name 修改角色状态
 * @param data data
 * @returns returns
 */
export const changeStatusApi = (data: { roleId: string | number; version: number; status: string }) => {
  return http.put<any>('/system/role/changeStatus', data, { loading: false })
}

/**
 * @name 删除角色信息
 * @param roleId roleId
 * @returns returns
 */
export const delRoleApi = (roleId: Array<string | number> | string | number) => {
  return http.delete<any>(`/system/role/${roleId}`)
}

/**
 * @name 下载模板
 * @returns returns
 */
export const importTemplateApi = () => {
  return http.downloadPost('/system/role/importTemplate', {})
}

/**
 * @name 导入数据
 * @returns returns
 */
export const importDataApi = (data: any) => {
  return http.post('/system/role/importData', data)
}

/**
 * @name 导出数据
 * @returns returns
 */
export const exportApi = (data: any) => {
  return http.downloadPost('/system/role/export', data)
}

/**
 * @name 查询角色已授权用户列表
 * @param query 参数
 * @returns 返回列表
 */
export const allocatedUserListApi = (query: UserQuery) => {
  return http.get<UserVO[]>(`/system/role/authUser/allocatedList`, query, { loading: true })
}

/**
 * @name 查询角色未授权用户列表
 * @param query 参数
 * @returns 返回列表
 */
export const unallocatedUserListApi = (query: UserQuery) => {
  return http.get<UserVO[]>(`/system/role/authUser/unallocatedList`, query, { loading: true })
}

/**
 * @name 取消用户授权角色
 * @param data data
 * @returns returns
 */
export const authUserCancelApi = (data: any) => {
  return http.put<any>('/system/role/authUser/cancel', data, { loading: false })
}

/**
 * @name 批量取消用户授权角色
 * @param data data
 * @returns returns
 */
export const authUserCancelAllApi = (data: any) => {
  return http.put<any>('/system/role/authUser/cancelAll', data, { loading: false })
}

/**
 * @name 授权用户选择
 * @param data data
 * @returns returns
 */
export const authUserSelectAllApi = (data: any) => {
  return http.put<any>('/system/role/authUser/selectAll', data, { loading: false })
}
